import modelComponent from './model'

const Model = {}

Model.install = function(Vue,options){
    if(Model.installed){
        return;
    }
    const tpl = Vue.extend(modelComponent)

    const modelTpl = new tpl()
    document.body.appendChild(modelTpl.$mount().$el);
    modelTpl.isShowModel = false
    const modelFn = function(opt){
        modelTpl.isShowModel = true
        if(opt){
            modelTpl.modelType = opt.type || "alert"
            modelTpl.modelTitle = opt.title || "提示"
            modelTpl.modelContent = opt.content || "提示内容"
            modelTpl.confirmColor = opt.color || "#007aff" 
           
            modelTpl.confirmText = opt.confirmText || "确定"
            modelTpl.cancelText = opt.cancelText || "取消"
        }
        modelTpl.successEvent = (arg)=>{
            modelTpl.isShowModel = false;
            if(opt.success) return opt.success(arg)
        }
    }

    Vue.prototype.$showModel = modelFn
}

export default Model